package cn.weezoo.jnademo;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/**
 * @author wenei
 * @date 2021-02-26 12:36
 */
public class JNATestPrintf {

    public interface Clibrary extends Library {
        Clibrary INSTANCE = (Clibrary) Native.loadLibrary(
                (Platform.isWindows() ? "msvcrt" : "c"), Clibrary.class);

        /*
         * 声明一个跟C语言的printf()一样的方法，参数类型要匹配
         * C语言的printf()方法原型如下：
         * int __cdecl printf(const char * __restrict__ _Format,...);
         */
        void printf(String format, Object... args);
    }

    public static void main(String...strings) {
        //调用
        Clibrary.INSTANCE.printf("Hello, World->%d",2019);
    }
}
